package com.learn.hibernatevalidator.chapter07.valueextractor.nongeneric;

import jakarta.validation.valueextraction.ExtractedValue;
import jakarta.validation.valueextraction.UnwrapByDefault;
import jakarta.validation.valueextraction.ValueExtractor;

import java.util.OptionalInt;

/**
 * @author: liyf
 * @create: 2025-01-19 13:56
 **/
@UnwrapByDefault
public class UnwrapByDefaultOptionalIntValueExtractor implements ValueExtractor<@ExtractedValue(type = Integer.class) OptionalInt> {
    @Override
    public void extractValues(@ExtractedValue(type = Integer.class) OptionalInt originalValue, ValueReceiver receiver) {
        receiver.value(null, originalValue.isPresent() ? originalValue.getAsInt() : null);
    }
}
